<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_810097_s50gcn082go.css">
    <link rel="stylesheet" href="../../css/common/reset.css">
    <link rel="stylesheet" href="../../css/addKeyWord.css">
</head>

<body style="background: #fff;">
    <!--列表 class="wechatPopup "-->
    <form action="?" class="layui-form">
        <ul>
            <li>
                <p class="fl labelText">关键词：</p>
                <p class="fl">
                    <input type="text" value="" placeholder="请填写关键词" id="word">
                </p>
            </li>
            <li>
                <p class="fl labelText">单量：</p>
                <div class="fl countNumBox fListsNum">
                    <input class="sub" id="orderNum-sub" value="-" type="button" />
                    <input type="text" value="1" class="" id="orderNum">
                    <input class="add" id="orderNum-add" value="+" type="button" />
                </div>
                <p class="fl">单</p>
            </li>
            <li>
                <p class="fl labelText">每单拍：</p>
                <div class="fl countNumBox fItemNum">
                    <input class="sub" id="orderSize-sub" value="-" type="button" />
                    <input type="text" value="1" class="" id="orderSize">
                    <input class="add" id="orderSize-add" value="+" type="button" />
                </div>
                <p class="fl">件</p>
            </li>
            <li>
                <input type="submit" value="确定提交" class="btn sureBtn" lay-submit="" lay-filter="Splan">
                <input type="button" value="取消调整" class="btn editBtn">
            </li>
        </ul>
    </form>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/jquery.cookie.js"></script>
    <script src="../../layui/layui.js"></script>
    <script>
        $(document).ready(function () {
            var t = $("#orderNum");
            //初始化数量为1,并失效减
            $('#orderNum-sub').attr('disabled', true);
            //数量增加操作
            $("#orderNum-add").click(function () {
                // 给获取的val加上绝对值，避免出现负数
                t.val(Math.abs(parseInt(t.val())) + 1);
                if (parseInt(t.val()) != 1) {
                    $('#orderNum-sub').attr('disabled', false);
                };
            })
            //数量减少操作
            $("#orderNum-sub").click(function () {
                t.val(Math.abs(parseInt(t.val())) - 1);
                if (parseInt(t.val()) == 1) {
                    $('#orderNum-sub').attr('disabled', true);
                };
            })
            var t1 = $("#orderSize");
            //初始化数量为1,并失效减
            $('#orderSize-sub').attr('disabled', true);
            //数量增加操作
            $("#orderSize-add").click(function () {
                // 给获取的val加上绝对值，避免出现负数
                t1.val(Math.abs(parseInt(t1.val())) + 1);
                if (parseInt(t1.val()) != 1) {
                    $('#orderSize-sub').attr('disabled', false);
                };
            })
            //数量减少操作
            $("#orderSize-sub").click(function () {
                t1.val(Math.abs(parseInt(t1.val())) - 1);
                if (parseInt(t1.val()) == 1) {
                    $('#orderSize-sub').attr('disabled', true);
                };
            })
        });

        layui.use(['layer', 'laydate', 'form'], function () {
            var layer = layui.layer, laydate = layui.laydate, form = layui.form;
            form.on('submit(Splan)', function () {
                var keyWords = {
                    word: $("#word").val(),
                    orderNum: $("#orderNum").val(),
                    orderSize: $("#orderSize").val()
                };
                // console.table(keyWords);
                // console.log(str);
                var oldKeyWordsList = localStorage.getItem('keyWordsList') || '[]'
                console.log('oldKeyWordsList', oldKeyWordsList);    // []
                // var keyWordsList = [...JSON.parse(oldKeyWordsList), keyWords]
                console.log('keyWords', keyWords)   // 这里也正常
                console.log("旧数据", JSON.parse(oldKeyWordsList))  // 这里正常
                oldKeyWordsList = JSON.parse(oldKeyWordsList)
                oldKeyWordsList.push(keyWords);  // 这了就不正常了，为啥  不知道  好像是他返回的是那个添加的数目而不是返回的数组  w
                // console.log("新数据", keyWordsList)
                localStorage.setItem('keyWordsList', JSON.stringify(oldKeyWordsList));

                console.log('storage', localStorage.getItem('keyWordsList'))
                // var merchantsId = $.cookie("merchantsId");
                // // var word = $("#word").val();
                // var orderNum = $("#orderNum").val();
                // console.log(orderNum)
                // var orderSize = $("#orderSize").val();
                // console.log(orderSize);
                // var word = $.cookie("word", $("#word").val());
                // var orderNum = $.cookie("orderNum", $("#orderNum").val());
                // var orderSize = $.cookie("orderSize", $("#orderSize").val());
                // return;
                var index = parent.layer.getFrameIndex(window.name);
                setTimeout(function () {
                    parent.layer.close(index);//关闭弹出层
                    parent.location.reload();//更新父级页面（提示：如果需要跳转到其它页面见下文）
                }, 2000);
                return false;
            });
        })
    </script>
</body>

</html>